package com.hooda.framework.aop;

import com.hooda.framework.annotations.Autowired;
import com.hooda.framework.annotations.Component;
import com.hooda.framework.orm.ConnectionManager;

import java.sql.SQLException;

/**
 * @author zhangzp
 * @version 1.0, 2021/9/9
 */
@Component
public class TransactionManager {

    @Autowired
    private ConnectionManager connectionManager;

    public void beginTransaction() throws SQLException {
        connectionManager.getCurrentThreadConnection().setAutoCommit(false);
    }

    public void commit() throws SQLException {
        connectionManager.getCurrentThreadConnection().commit();
    }

    public void rollback() throws SQLException {
        connectionManager.getCurrentThreadConnection().rollback();
    }
}
